Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Journeys In-App Plugin #6

Merged
merged 10 commits into from
Dec 21, 2023
Merged

Journeys In-App Plugin #6

merged 10 commits into from
Dec 21, 2023

Conversation

clabland
Copy link

Add Customer.io In-App Plugin integration, can be loaded via snippet:

<script>
!function(){var analytics=window.analytics=window.analytics||[];if(!analytics.initialize)if(analytics.invoked)window.console&&console.error&&console.error("Snippet included twice.");else{analytics.invoked=!0;analytics.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","reset","group","track","ready","alias","debug","page","once","off","on","addSourceMiddleware","addIntegrationMiddleware","setAnonymousId","addDestinationMiddleware"];analytics.factory=function(e){return function(){var t=Array.prototype.slice.call(arguments);t.unshift(e);analytics.push(t);return analytics}};for(var e=0;e<analytics.methods.length;e++){var key=analytics.methods[e];analytics[key]=analytics.factory(key)}analytics.load=function(key,e){var t=document.createElement("script");t.type="text/javascript";t.async=!0;t.src="https://cdp.customer.io/v1/analytics-js/snippet/" + key + "/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(t,n);analytics._writeKey=key;analytics._loadOptions=e};analytics.SNIPPET_VERSION="4.15.3";
analytics.load(
    "CDP_WRITE_KEY",
    { 
        "integrations": {
            "Customer.io In-App Plugin": { 
                siteId: "YOUR_JOURNEYS_SITE_ID"
            }
        }
    }
);
analytics.page();
</script>

Or bundled in an app:

import { AnalyticsBrowser } from '@customerio/cdp-analytics-browser'

const analytics = AnalyticsBrowser.load(
  { writeKey "YOUR_WRITE_KEY" },
  {
    integrations: { 
        "Customer.io In-App Plugin": { 
            siteId: "YOUR_SITE_ID",
        },
    },
  },
);

.gitignore Outdated Show resolved Hide resolved
packages/browser/src/plugins/in-app-plugin/events.ts Outdated Show resolved Hide resolved
packages/browser/src/plugins/in-app-plugin/index.ts Outdated Show resolved Hide resolved
packages/browser/src/plugins/in-app-plugin/index.ts Outdated Show resolved Hide resolved
packages/browser/src/plugins/in-app-plugin/index.ts Outdated Show resolved Hide resolved
packages/browser/src/plugins/in-app-plugin/index.ts Outdated Show resolved Hide resolved
_eventTarget.addEventListener(event, settings?.events as EventListenerOrEventListenerObject);
});
['messageShown', 'messageDismissed', 'messageError'].forEach((event) => {
Gist.events.on(event, (message: any) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the gist sdk have the equivalent of an "unload" function? (to deregister these events)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed this offline, Gist isn't actually using event handlers, just an array of callback functions to call. So we think this is ok.

@clabland clabland merged commit a70aac6 into main Dec 21, 2023
1 check passed
@clabland clabland deleted the in-app-plugin branch December 21, 2023 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants